<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    var maxNumber = function(digits) {
      const arr = digits.split(''); // 将字符串转成数组
      let hash = {}; // 定义hash用来计算
      for (let i = 0; i < arr.length; i++) {
        // 如果当前hash中没有该元素 数量为1 如果有 数量+=1
        hash[arr[i]] = !hash[arr[i]] ? 1 : (hash[arr[i]] += 1);
      }
      // 根据键值排序键名
      let keys = Object.keys(hash);
      keys.sort((a, b) => {
        return hash[b] - hash[a];
      });
      return `${keys[0]}出现次数最多，出现${hash[keys[0]]}次`;
    };
    console.log(maxNumber('hajjfhlhhffhhhh'));
  </script>
</html>
